<template>
	<div class="view">
		<div class="tab">
			<view class="tabs-item">
				<view class="warp" @click="selectCity">
					<view>{{ cityName.title || '选择您的城市' }}</view>
					<image src="/static/images/ic_drop_down.png" />
				</view>
				<view class="warp" @click="showHospital = !showHospital">
					<view>{{ hospitalName ? hospitalName : "医院筛选" }}</view>
					<image src="/static/images/ic_drop_down.png" :style="showHospital ? 'transform: rotate(180deg);' : ''" />
				</view>
			</view>
			<view class="hospitalscreen" v-show="showHospital">

				<view class="hospital-item" v-for="(item,index) in hospitalList" :key='item.id'
					@click="screenClick(item,index)">
					<text :class="item.isChecked ? 'is-check' : '' ">{{item.text}}</text>
				</view>

			</view>
		</div>


		<div class="hospitalList">
			<div v-for="(item, index) in list" :key="index" class="item"
				@click="to('/pages/IndexPages/hospitalDetails/main?id=' + item.id)">
				<div>
					<span>{{ item.hospitalName }}</span>
					<span>{{ item.hospitalGrade }}</span>
					<span>{{ item.hospitalType }}</span>
				</div>
				<div>{{ item.hospitalAddress }}</div>
				<div>
					<p v-for="(val, k) in item.labelList" :key="k">{{ val }}</p>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import {
		gethotHospital
	} from "@/apis/request.js";

	export default {
		data() {
			return {
				showHospital: false,
				finished: false,
				list: [],
				hospitalName: "",
				cityName: {
					id: 350200,
					title: '厦门市'
				},
				hospitalType: "",
				pageNo: 1,
				hospitalList: [{
						text: "综合",
						isChecked: false
					},
					{
						text: "妇科",
						isChecked: false
					},
					{
						text: "中医",
						isChecked: false
					},
					{
						text: "骨科",
						isChecked: false
					}
				]
			};
		},
		methods: {
			//选择城市
			selectCity() {
				let that = this
				uni.navigateTo({
					url: '/pages/IndexPages/ChooseCity/main',
					events: {
						changeCity(data) {
							let city = uni.setStorageSync('city', data) || {
								id: 350200,
								title: '厦门市'
							}
							that.cityName = data
							this.list = [];
							that.getList();
						}
					}
				})
			},
			screenClick(item, index) {
				this.hospitalType = index
				this.showHospital = false
				this.list = [];
				this.getList()
			},
			async onConfirm(e) {
				this.finished = false;
				this.hospitalType = e.mp.detail.value.text;
				this.list = [];
				this.pageNo = 1;
				this.showHospital = false;
				this.getList();
			},
			to(url) {
				uni.navigateTo({
					url
				});
			},
			async getList() {
				if (!this.finished) {
					const data = await gethotHospital({
						cityId: this.cityName.id,
						hospitalType: this.hospitalType,
						pageNo: this.pageNo,
						pageSize: 10
					});
					if (data.records.length == 0) {
						this.finished = true;
					}
					this.list.push(...data.records);
					uni.stopPullDownRefresh();
				}
			}
		},
		onShow() {
			Object.assign(this.$data, this.$options.data());
			this.cityName = uni.getStorageSync('city')
			this.getList();
		},
		onReachBottom() {
			this.pageNo++
			this.getList();
		},
		onPullDownRefresh() {
			this.list = [];
			this.finished = false;
			this.pageNo = 1;
			this.getList();
		}
	};
</script>
<style lang="scss" scoped>
	.view {
		width: 100%;
		height: auto;
		background-color: #f1efef;

		.tab {
			position: fixed;
			z-index: 10;
			display: flex;
			align-items: center;
			height: 100rpx;
			border-bottom: 1rpx solid #F1F1F1;
			width: 100vw;
			background-color: #ffffff;

			.hospitalscreen {
				top: 100rpx;
				left: 0;
				position: absolute;

				.hospital-item {
					background-color: #FFFFFF;
					display: flex;
					width: 100vw;
					align-items: center;
					height: 120rpx;
					justify-content: center;
					border-bottom: 1rpx solid #dadada85;

					.is-check {
						color: #ff5457;
					}
				}
			}

			.tabs-item {
				display: flex;
				width: 100%;
				height: 100rpx;

				.warp {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 50%;
					font-size: 30rpx;
					position: relative;

					image {
						transition: all .3s linear;
						margin-left: 5rpx;
						width: 18rpx;
						height: 12rpx;
					}
				}
			}

			.navigator-hover {
				background: rgba(0, 0, 0, 0);
			}

			.warp {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 50%;
				font-size: 30rpx;

				img {
					margin-left: 5rpx;
					width: 18rpx;
					height: 12rpx;
				}
			}
		}

		.hospitalList {
			margin-top: 91rpx;

			.item {
				padding: 30rpx;
				border-bottom: 1rpx solid #F1F1F1;
				background-color: #ffffff;

				div:nth-child(1) {
					span {
						margin-right: 10rpx;
						display: inline-block;
					}

					span:nth-child(1) {
						font-size: 30rpx;
					}

					span:nth-child(2) {
						font-size: 22rpx;
						background: linear-gradient(#f5a91d 0%, #f4a200 53%, #f7c372 100%);
						color: #ffffff;
						border-radius: 4rpx;
						padding: 5rpx 10rpx;
					}

					span:nth-child(3) {
						font-size: 22rpx;
						background-color: #47ABF7;
						color: #ffffff;
						border-radius: 4rpx;
						padding: 5rpx 10rpx;
					}
				}

				div:nth-child(2) {
					margin: 10rpx 0rpx;
					color: #ababab;
					font-size: 22rpx;
				}

				div:nth-child(3) {
					display: flex;
					align-items: center;

					p:nth-child(1) {
						padding: 8rpx 10rpx;
						color: #edb344;
						font-size: 20rpx;
						margin-right: 10rpx;
						border: 1rpx solid #e9c278;
						border-radius: 4rpx;
						background-color: #ffffff;
					}

					p:nth-child(2) {
						padding: 8rpx 10rpx;
						color: #dd1d1a;
						font-size: 20rpx;
						margin-right: 10rpx;
						border: 1rpx solid #dd1d1a;
						border-radius: 4rpx;
						background-color: #ffffff;
					}
				}
			}
		}
	}
</style>